package com.itheima.apitest.datetest2;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

//两种阶段时间获取练习

public class DateTest04 {
    public static void main(String[] args) {
        LocalDate localDate1 = LocalDate.of(2020,11,12);
        LocalDate localDate2 = LocalDate.of(2080,7,11);

        //period
        Period period = Period.between(localDate1, localDate2);
        System.out.println(period);
        //获得这段时间的年数
        int years = period.getYears();
        System.out.println(years);
        //获得这段时间的月数
        int months = period.getMonths();
        System.out.println(months);
        //获得这段时间的天数
        int days = period.getDays();
        System.out.println(days);
        //获得这段时间的总月数
        long totalMonths = period.toTotalMonths();
        System.out.println(totalMonths);

        System.out.println("-----------------");

        //duration
        LocalDateTime localDateTime3 = LocalDateTime.of(2020, 11, 11, 11, 11, 11);
        LocalDateTime localDateTime4 = LocalDateTime.of(2020, 11, 11, 11, 11, 23);
        Duration duration = Duration.between(localDateTime3, localDateTime4);
        System.out.println(duration);
        //获得此时间间隔的秒
        long toSeconds = duration.toSeconds();
        System.out.println(toSeconds);
        //获得此时间间隔的毫秒
        long toMillis = duration.toMillis();
        System.out.println(toMillis);
        //获得此时间间隔的纳秒
        long toNanos = duration.toNanos();
        System.out.println(toNanos);

    }
}
